# 斐波那契数列
def fib(n):
    if n < 2:
        return n
    else:
        return fib(n - 2) + fib(n - 1)

print(fib(7))

# 快排,return在最里层
def quick(qlist):
    if len(qlist) == 0:
        return qlist
    else:
        qb = qlist[0]
        qa = quick([l for l in qlist[1:] if l <= qb])
        qc = quick([m for m in qlist[1:] if m > qb])
        return qa + [qb] + qc


print(quick([12, 42, 2, 1, 25, 632]))

# 随机插入排序，return在最外层for返回
def insertQuick(qlist):
    for i in range(len(qlist)):
        key = qlist[i]
        j = i - 1
        while j >= 0 and key < qlist[j]:
            qlist[j + 1] = qlist[j]
            j -= 1
            qlist[j + 1] = key
    return qlist

print(insertQuick([23, 3, 45, 2, 43]))

# 99乘法表
def n_n():
    for i in range(1, 10):
        for j in range(1, i+1):
            print(f'{j}*{i}={j*i}  ', end=' ')
        print('\t')


print(n_n())


# 统计字符串中出现次数最多的字符和次数
def str():
    s1 = "djaofanfgehroajffdk"
    d1 = {}
    for s in s1:
        if s not in d1:
            d1[s] = 1
        else:
            d1[s] += 1
    for k, v in d1.items():
        if v == max(d1.values()):
            print(k, v)


print(str())

# Switch语句
def sw():
    d_sw = {
        "k1" : 1,
        "k2" : "zkk",
        "k3" : [12, 23, 34]
    }
    print(d_sw["k3"])
    return "无所吊谓！"

print(sw())

# filter()筛选功能
def name(n):
    if n.startswith('周'):
        return True

print(list(filter(name, ["周恩来", "周抗抗", "王小丽", "黄婷"])))



# map()映射方法
print(list(map(lambda a: a **3, [2, 3, 4, 5])))

# 获取list索引位置
def l_index():
    l1 = [23, 542, 525, 5223]
    print(l1.index())
# 判断字符串中大写的几个，小写的几个
def strBandS():
    s1 = "AAAAASDASdasdasdsaD"
    小写 = 0
    大写 = 0
    for s in s1:
        if s.islower():
            小写 += 1
        else:
            大写 += 1
    print(f"大写的{大写}个，小写的{小写}个" )


strBandS()

# 修改元组内部元素不可修改的元素
def tp():
    tp1 = (2, 3, 41, "we", [32, 42])
    tp1[4].extend([3434,45235,525])
    print(tp1)


tp()




# 列表推导式
ll1 = [i for i in range(10)]
print(ll1)
# 集合推导式
set1 = {i for i in range(10)}
print(set1)
# 字典推导式
l1 = [23, 234, 5235]
d1 = {i:l1[i] for i in range(len(l1))}
print(d1)

# 函数嵌套 直接由装饰器包含了函数嵌套
# 迭代器
def ddq():
    """
    1、6种可迭代对象
    :return:
    """
    list1 =[123, 131, 51, 5]
    list2 = list1.__iter__()
    print(list2.__next__())
    print(list2.__next__())
    print(list2.__next__())

ddq()

# 生成器
def scq():
    a = 123
    b = 234
    yield a
    yield b
cc = scq()
print(cc.__next__())
print(cc.__next__())


# 装饰器
def wapper(name):
    i = 12345
    def inner(*args, **kwargs):
        print(i)
        reName = name(*args, **kwargs)
        print(args, kwargs)
        return reName
    return inner

@wapper
def game(username, password):
    print(username, password)
    return "game返回到，游戏开始了"

game("zhoukangkang", password="123456")